package org.llc.flink.study.gof.state

class Context(private var state: State) {

  private[state] val stateA = new ConcreteStateA
  private[state] val stateB = new ConcreteStateB

  def setState(state: State): Unit ={
    this.state = state
  }

  def request(): Unit ={
    state.handle(this)
  }

}

object Context{
  def main(args: Array[String]) {
    // 设置Context的初始状态为ConcreteStateA
    val context = new Context(new ConcreteStateA());

    // 不断地进行请求，同时更改状态
    context.request();
    context.request();
    context.request();
    context.request();
  }

}
